package workers;

import java.util.concurrent.BlockingQueue;

import model.Software;
import workerUIs.StepFrame;
import workflow.step.UIImplementationStep;

public class UIStepWorker extends AbstractStepSwingWorker {

	private final BlockingQueue<Software> outputQueue;
	private final BlockingQueue<Software> inputQueue;
	private StepFrame nextFrame;

	public UIStepWorker(StepFrame frame, BlockingQueue<Software> inputQueue, BlockingQueue<Software> outputQueue,  StepFrame nextFrame) {
		super(frame);
		this.inputQueue = inputQueue;
		this.outputQueue = outputQueue;
		this.nextFrame = nextFrame;
	}

	@Override
	protected Software doInBackground() throws Exception {
		this.software = this.inputQueue.take();
		new UIImplementationStep().doStep(getSoftware());
		this.outputQueue.put(this.software);
		return this.software;
	}
	
	@Override
	protected void done() {
		super.done();
		if (inputQueue.isEmpty()) {
			getFrame().getNextButton().setEnabled(false);
		}
		this.nextFrame.getNextButton().setEnabled(true);
	}

}
